package cn.zqy.demo.day11.demo05;

import cn.zqy.demo.day11.red.OpenMode;

import java.util.ArrayList;
import java.util.Random;

public class Bootstrap {
    public static void main(String[] args) {
        MyRed red = new MyRed("红包");

  /*      // 平均分
        OpenMode avg = new OpenMode() {
            @Override
            public ArrayList<Integer> divide(int totalMoney, int totalCount) {
                int num = totalMoney  / totalCount;
                int mod = totalMoney  % totalCount;
                ArrayList<Integer>  list =  new ArrayList<>();
                for (int i = 0; i < totalCount - 1; i++) {
                    list.add(num);
                }
                System.out.println(num+mod);
                list.add(num + mod);
                return list;
            }
        };
        red.setOpenWay(avg);
        red.setOwnerName("悟空");
*/

        // 随机分
        OpenMode av = new OpenMode() {
            @Override
            public ArrayList<Integer> divide(int totalMoney, int totalCount) {
                int modMoney = totalMoney;
                int modCount = totalCount;
                Random r = new Random();
                ArrayList<Integer>  list =  new ArrayList<>();
                for (int i = 0; i < totalCount - 1; i++) {
                    // 最少1分钱
                    int h = r.nextInt((modMoney/ modCount)*2) + 1;
                    list.add(h);
                    modCount--;
                    modMoney = modMoney - h;
                    System.out.println( "modeMoney"+modMoney);

                }
                list.add(modMoney);
                return list;
            }
        };
        red.setOpenWay(av);
        red.setOwnerName("八戒");
    }
}
